package gui.author;

import gui.CAControl;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import caobject.Conference;
import caobject.User;

/**
 * Conference Assistant Submit Paper North Panel.
 * 
 * @author Bob Rankin
 * @author Brian M. Luger
 * @version 12/3/2011
 */
@SuppressWarnings("serial")
public class AuthorNorthPanel extends JPanel implements Observer 
{
	/*
	 * Panel Grids
	 */
	private final JPanel my_gridOne = new JPanel();
	private final JPanel my_gridTwo = new JPanel();
	private final JPanel my_gridThree = new JPanel();
	
	/*
	 * Panel Text Fields
	 */
	private final JTextField my_confField
 	= new JTextField(10);
	private final JTextField my_userField
	 	= new JTextField(10);
	private final JTextField my_roleField
 	= new JTextField(10);
	
	// Panel Conference Reference
	private final Conference my_conf;
	
	// Panel Control Reference
	private final CAControl my_control;
	
	/**
	 * Conference Assistant North Panel Constructor
	 * 
	 * @param the_conf Coference Reference
	 * @param the_control Control Reference
	 */
	public AuthorNorthPanel(final Conference the_conf,
		final CAControl the_control, final User the_user) 
	{
		my_conf = the_conf;
		my_control = the_control;
		my_control.setSelectedConference(the_conf.getTitle());
		my_control.setSelectedUser(the_user.getUserName());
		my_control.setSelectedRole("AUTHOR");
		my_control.addObserver(AuthorNorthPanel.this);
		
		setup();
	}
	
	/**
	 * Panel Setup Method
	 */
	private void setup() 
	{
		my_confField.setEditable(true);
		setLayout(new GridLayout(1,3));
		
		// Grid One...
		my_gridOne.setLayout(
				new FlowLayout(FlowLayout.CENTER));
		my_gridOne.add(new JLabel("Conference: "));
		
		my_gridOne.addFocusListener(new FocusListener() {

			@Override
			public void focusGained(FocusEvent arg0) {
				// Do Nothing
			}

			@Override
			public void focusLost(FocusEvent arg0) {
				// TODO Add Defensive Tests...
				my_control.setSelectedConference(
						my_confField.getText());
			}
			
		});
		
		my_confField.setEditable(false);
		my_gridOne.add(my_confField);
		add(my_gridOne);
		
		my_userField.setEditable(true);
		// Grid Two...
		my_gridTwo.setLayout(
				new FlowLayout(FlowLayout.CENTER));
		my_gridTwo.add(new JLabel("User: "));
		
		my_userField.addFocusListener(new FocusListener() {

			@Override
			public void focusGained(final FocusEvent event) {
				// Do Nothing...
			}

			@Override
			public void focusLost(final FocusEvent event) {
				// TODO Add Defensive Tests...
				my_control.setSelectedUser(
						my_userField.getText());

			}
			
		});
		my_userField.setEditable(false);
		my_gridTwo.add(my_userField);
		
		my_roleField.setEditable(true);
		add(my_gridTwo);
		
		// Grid Three...
		my_gridThree.setLayout(
				new FlowLayout(FlowLayout.CENTER));
		my_gridThree.add(new JLabel("Role: "));
		my_roleField.setEditable(false);
		my_gridThree.add(my_roleField);
		add(my_gridThree);
	}
	
	/**
	 * Method used to update the panel
	 */
	@Override
	public void update(final Observable the_observable, 
			final Object the_obj) 
	{
		my_confField.setText(
				my_control.getSelectedConference());
		my_userField.setText(my_control.getSelectedUser());
		my_roleField.setText(my_control.getSelectedRole());
		
	}
}
